home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: wzjn@ix.netcom.com (KPN )
- Newsgroups: comp.lang.c
- Subject: Re: Help for a float problem
- Date: 9 Feb 1996 20:47:24 GMT
- Organization: Netcom
- Message-ID: <4fgbss$nqm@ixnews6.ix.netcom.com>
- References: <AMCHAVAN.96Jan25112007@ac2.hq.eso.org> <4f6tt6$rt1@news.cencom.net> <311A83D1.57A3@feith.com> <4fe4m4$f1c@news.ee.net> <4fflin$92t@murrow.corp.sgi.com> <4fgal6$fm8@lois.Read.TASC.COM> <4fgbdc$92t@murrow.corp.sgi.com>
- NNTP-Posting-Host: ix-frm-ma2-04.ix.netcom.com
- X-NETCOM-Date: Fri Feb 09 12:47:25 PM PST 1996
-
- Good Afternoon,
-
- Using æHow To Program C (second edition)Æ by Deitel & Deitel, IÆm
- trying to do on page 92, example 3.17. IÆm not sure, but believe that
- my problem is where to use a æfloatÆ.
-
- I want to ask the user to enter gallons used, which of course, could be
- 12.8. However, with the same line, I want the user to enter æ-1Æ if
- they choose to end the program.
-
- The way it is written so far, the user can successfully exit the
- program with a -1. The user can also successfully enter whole numbers
- and get an answer. My problem arises when I enter (again) 12.8 ... the
- program goes in to an infinate loop! eh?
-
- Conversely, if I define gallons as a float, the program does not
- recognize the æ-1Æ as an end of program. eh?
-
- Someone have the time to tell me where my problem lies? IÆm not in a
- class, this is only for my benefit, but I would like to know what to do
- here / what the æwork-aroundÆ is. Here is my code:
-
- #include <stdio.h>
-
- main()
- {
- int miles, answer, gallons;
-
- printf("Enter the gallons used (-1 to end): \n");
- scanf("%d", &gallons);
-
- while (gallons != -1)
- {
- printf("Enter the miles driven:\n");
- scanf("%d", &miles);
-
- answer = miles / gallons;
- printf("The miles / gallons for this tank was %d\n", answer);
-
- printf("Enter the gallons used (-1 to end): \n");
- scanf("%d", &gallons);
-
- /* printf("Enter the miles driven:\n");
- scanf("%d", &miles); */
- }
- return 0;
- }
-
-
- Thank you for your help,
-
- kevin
-
- ôWhen their numbers dwindled from 50 down to 8, the remaining dwarfs
- began to suspect æHungryÆ.ö
-
-